package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.mappers.QuestionMapper;
import com.tanhua.model.domain.Question;
import com.tanhua.service.QuestionApi;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class QuestionApiImpl implements QuestionApi {

    @Autowired
    private QuestionMapper questionMapper;

    /**
     * 通过用户id查询用户的陌生人信息
     * @param id 用户id
     * @return
     */
    @Override
    public Question getById(Long id) {
        QueryWrapper qw = new QueryWrapper();
        qw.eq("user_id", id);
        Question question = questionMapper.selectOne(qw);
        return question;
    }

    /**
     * 保存用户的陌生人信息
     * @param question 用户设置的陌生人信息
     */
    @Override
    public void save(Question question) {
        questionMapper.insert(question);
    }

    /**
     * 修改用户的陌生人信息
     * @param question 用户修改成的陌生人信息
     */
    @Override
    public void update(Question question) {
        QueryWrapper qw = new QueryWrapper();
        qw.eq("user_id", question.getUserId());
        questionMapper.update(question, qw);
    }
}